package com.gm.wholesale.module.unit.model;

import android.util.ArrayMap;

import com.gm.commonlib.base.baseBean.BaseListResp;
import com.gm.commonlib.base.baseBean.BasePageData;
import com.gm.commonlib.base.baseBean.BaseResp;
import com.gm.commonlib.base.baseView.IBaseView;
import com.gm.commonlib.network.BaseHttpObserver;
import com.gm.commonlib.network.HttpClient;
import com.gm.commonlib.network.HttpServicesHolder;
import com.gm.wholesale.module.order.api.IOrderApi;
import com.gm.wholesale.module.order.bean.CreateOrderBean;
import com.gm.wholesale.module.unit.api.IUnitApi;
import com.gm.wholesale.module.unit.bean.UnitBean;

import io.reactivex.Observable;

public class UnitModel {

    // todo 获取单位列表数据
    public static void getUnits(IBaseView iBaseView,
                                BaseHttpObserver<BasePageData<UnitBean>> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IUnitApi, BasePageData<UnitBean>>() {
            @Override
            public Observable<BasePageData<UnitBean>> getHttpObservable(IUnitApi instance) {
                return instance.getUnits();
            }
        }, observer);
    }

    //修改单位
    public static void updateUnit(IBaseView iBaseView,
                                  long uid, ArrayMap<String, Object> data,
                                  BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IUnitApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(IUnitApi instance) {
                return instance.updateUnit(uid, data);
            }
        }, observer);
    }


    //创建单位
    public static void createUnit(IBaseView iBaseView,
                                  ArrayMap<String, Object> data,
                                  BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IUnitApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(IUnitApi instance) {
                return instance.createUnit(data);
            }
        }, observer);
    }


    //创建单位
    public static void deleteUnit(IBaseView iBaseView,
                                  long id,
                                  int version,
                                  BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IUnitApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(IUnitApi instance) {
                return instance.deleteUnit(id,version);
            }
        }, observer);
    }

}
